#!/usr/bin/env python
# -*- coding:utf-8 -*-

# 需求：获取豆瓣电影滚动时返回的电影数据
# 思路：屏幕滚动时会发起分页请求https://movie.douban.com/j/chart/top_list
#      参数为：type: start，interval_id，limit,action
#      响应数据对应的是一组json数据。

import requests
import json
import io

if __name__ == "__main__":
    # 1 .指定url
    url = "https://movie.douban.com/j/chart/top_list"
    # 2.请求之前进行UA伪装
    headers = {
        'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Mobile Safari/537.36'
    }

    param = {
        'type':'24',
        'interval_id':'100:90',
        'action':'',
        'start':'60',
        'limit': '20'
    }

    response = requests.get(url=url,params=param,headers=headers)

    list_data = response.json()

    fp = file('test.json', 'w')
    json.dump(obj=list_data,fp=fp,ensure_ascii=False)